﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LeEdu.MODEL;
using LeEdu.DAL;
using System.Linq.Expressions;

namespace LeEdu.BLL
{
   public class BaseBLL<T>where T:class
    {
       protected BaseDAL<T> dal = new BaseDAL<T>();
       /// <summary>
       /// 添加
       /// </summary>
       /// <param name="t">对象</param>
       /// <returns></returns>
       public bool AddEntity(T t)
       {
           return dal.AddEntity(t);
       }
       /// <summary>
       /// 删除
       /// </summary>
       /// <param name="t">对象</param>
       /// <returns></returns>
       public bool Del(T t)
       {
           return dal.Del(t);
       }
       /// <summary>
       /// 修改
       /// </summary>
       /// <param name="t"></param>
       /// <returns></returns>
       public bool Edit(T t)
       {
           return dal.Edit(t);
       }

       /// <summary>
       /// 获取集合信息
       /// </summary>
       /// <returns></returns>
       public virtual List<T> GetAll()
       {
           return dal.GetAll();
       }

       /// <summary>
       /// 获取一条数据
       /// </summary>
       /// <param name="whereLambda">Lambda表达式</param>
       /// <returns></returns>
       public T getEntity(Expression<Func<T, bool>> whereLambda)
       {
           return dal.getEntity(whereLambda);
       }
       /// <summary>
       /// 获取对象的集合
       /// </summary>
       /// <param name="whereLambda">Lambda表达式</param>
       /// <returns></returns>
       public List<T> getEntityList(Expression<Func<T, bool>> whereLambda)
       {
           return dal.getEntityList(whereLambda);
       }
       /// <summary>
       /// 根据编号查一条数据
       /// </summary>
       /// <param name="id"></param>
       /// <returns></returns>
       public T Search(int id)
       {
           return dal.Search(id);
       }
       //查询
       public IQueryable<Courses> chaxun(System.Linq.Expressions.Expression<Func<Courses, bool>> wherelambda)
       {

           return dal.chaxun(wherelambda);
       }
       /// <summary>
       /// 分页
       /// </summary>
       /// <typeparam name="A">排序字段</typeparam>
       /// <param name="orderLambda">排序条件</param>
       /// <param name="WhereLambda">查询条件</param>
       /// <param name="pageindex">页码</param>
       /// <param name="pagesize">每页条数</param>
       /// <param name="pageCount">总页数</param>
       /// <param name="total">总条数</param>
       /// <param name="isasc">排序方式（默认升序）</param>
       /// <returns>对象集合（List<T>）</returns>
       public virtual List<T> getEntityPagging<A>(Expression<Func<T, A>> orderLambda, Expression<Func<T, bool>> WhereLambda, int pageindex, int pagesize, out int total, out int pageCount, bool isasc = true)
       {    
           return dal.getEntityPagging(orderLambda, WhereLambda, pageindex, pagesize, out total, out pageCount, isasc);

       }

       public string DateStringFromNow(DateTime dt)
       {
           return dal.DateStringFromNow(dt);
       }
    }
}
